#include "types.h"

/*____________________________________________________________________________*/

cmd_mmu str2cmd_mmu(char* str){
    if(strncmp(str,"PT",2)==0 )
	    return InPt;
	else if(strncmp(str,"ADD",3)==0 )
		return InAdd;
	else if(strncmp(str,"FLUSH",5)==0 )
		return InFlush;
	else if(strncmp(str,"KILL",4)==0 )
		return InKill_mmu;
	else
		return INERROR;
}

/*____________________________________________________________________________*/

s_processus str2s_processus(char* str){
	if(strncmp(str,"RUN",3)==0 )
		return InRun;
	else if(strncmp(str,"STOP",4)==0 )
		return InStop;
	else if(strncmp(str,"KILL",4)==0 )
		return InKill_proc;
	else
		return INERROR;
}

/*____________________________________________________________________________*/

cmd_os  str2cmd_os(char* str){
    if(strncmp(str,"CREATE",6)==0 )
	    return InCreate;
	else if(strncmp(str,"LISTE",5)==0 )
		return InListe;
	else if(strncmp(str,"END",3)==0 )
		return InEnd;
	else if(strncmp(str,"KILL",4)==0 )
		return InKill_os;
	else
		return INERROR;
}

/*____________________________________________________________________________*/

/*!
 *  \brief creation la table des cadres
 * void dialogue_utilisteur( _processus_simple myPS);
 * @param   *bitmap  TODO faire la description
 * @param   cadre_max  le maximale de cadre
 */
void creation_table_cadre(Frame_table *bitmap,int cadre_max){
  int i;
   bitmap->frame_num=cadre_max;
   bitmap->fte= malloc(cadre_max*sizeof(int));

   for(i = 0; i < cadre_max; i++) {
      bitmap->fte[i].is_bound = 0;
       bitmap->fte[i].proc_id = 0;
    }
}

/*____________________________________________________________________________*/

/*creation la table des pages*/
void creation_table_page(Page_table *table, int page_max){
    int i;

    table->page_num=page_max;
    table->pte= malloc(page_max*sizeof(Page_table_entry));

    for(i = 0; i < page_max; i++) {
    	table->pte[i].frame_num= 0;
    	table->pte[i].dirty = False;
    	table->pte[i].valid = False;
    }
}

/*____________________________________________________________________________*/

void initDonnees(Donnees *d, int pagesParProc, int nCadres){
	d->nCreer = 0;
	d->nTuer = 0;

	d->tableProc.tete = NULL;
	d->tableProc.encours = NULL;

	d->detruire = False;

	d->tableCadres.frame_num = nCadres;
	d->tableCadres.fte =
			(Frame_table_entry*) malloc(nCadres*sizeof(Frame_table_entry));

	d->pagesParProc = pagesParProc;

	d->log = fopen(LOG_FILE, "w");

	if(d->log==NULL){
		perror("Erreur pour créer un fichier de log.");
		exit(EXIT_FAILURE);
	}
}

/*____________________________________________________________________________*/
